#pragma once

#include <MCF/Code/StdMCF.hpp>
#include <MCF/Code/WindowBaseClass.hpp>
#include <MCF/Code/ProgressBarClass.hpp>
#include <MCF/Code/TabControlClass.hpp>
#include <vector>
#include "LogEditBoxClass.hpp"
#include "AsyncWriteTextControlClass.hpp"
#include "AsyncWriteProgressBarClass.hpp"

class TabControlPanelClass sealed : public MCF::TabDialogBaseClass {
private:
	static const int _CONTROLS_TO_LOCK_WHEN_RUNNING[];
private:
	static bool _EventGUISetStatusTextProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);
	static bool _EventGUISetProgressProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);
	static bool _EventGUISetSubProgressProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);

	static bool _ThreadEventGenericInitializeProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);
	static bool _ThreadEventGenericAdminPrivResultProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);

	static bool _ThreadEventGUILockProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);
	static bool _ThreadEventGUIUnlockProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);
	static bool _ThreadEventGUIAcceleratorProc(std::intptr_t nContext, std::intptr_t nArg1, std::intptr_t nArg2, std::intptr_t nArg3);
private:
	long _m_lOptionLockCount;
	long _m_lButtonLockCount;
	bool _m_bResourceLoaded;
	std::vector<bool> _m_vecChildrenLockFlags;

	MCF::WindowBaseClass _m_edtFontPath;
	MCF::WindowBaseClass _m_edtROMPath;
	MCF::WindowBaseClass _m_edtSDCardPath;

	LogEditBoxClass _m_edtLogEditBox;
	AsyncWriteTextControlClass _m_txtStatus;
	AsyncWriteProgressBarClass _m_ProgressBar;
	AsyncWriteProgressBarClass _m_SubProgressBar;
public:
	TabControlPanelClass(HWND hParent);
	virtual ~TabControlPanelClass();
protected:
	virtual void _PostSubclass() override;
	virtual void _PreUnsubclass() override;

	virtual bool _OnInitDialog(HWND hDefControl, LPARAM lInitParam) override;
	virtual void _OnDestroy() override;
	virtual bool _OnCommand(WORD wNotifyCode, int nControlID, HWND hSender) override;
private:
	void _OnAdminPrivResult(bool bHasAdminPriv);

	void _OnGUILock();
	void _OnGUIUnlock();

	void _LockOptionControls();
	void _UnlockOptionControls();
	void _LockCommandButtons();
	void _UnlockCommandButtons(bool bResourceLoaded);

	void _SetDoesSDCardUseFile(bool bToUse);
	void _SetHideFixedDisks(bool bToHide);
	void _ClearDiskList();
	void _RefreshDiskList();

	void _OnClickPickFont();
	void _OnClickPickROM();
	void _OnClickPickSD();
	void _OnClickSetHideFixedDisks();

	void _Initialize();

	bool _LoadResources();
	void _UnloadResources();

	void _Trace();
	void _Go();

	void _CommandLoad();
	void _CommandTrace();
	void _CommandGo();
	void _CommandReset();
};
